package com.yitao.cms.controller.expressage;

import com.skipper.base.bean.DataOutput;
import com.skipper.base.bean.PagedOutput;
import com.yitao.client.constant.OrderStatusEmnu;
import com.yitao.cms.config.aopLog.LogAnnotation;
import com.yitao.cms.service.expressage.ExpressageMatchingDetailCmsService;
import com.yitao.cms.service.expressage.ExpressageSubscribeLogCmsService;
import com.yitao.cms.service.order.CmsServicesCompanyInfoService;
import com.yitao.cms.vo.expressage.ExpressageMatchingDetailVo;
import com.yitao.cms.vo.expressage.ServicesCompanyInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @Date: 2019/6/12 11:26
 * @Author: Kien
 */
@Api(value = "cms/expressage", description = "物流信息相关", tags = {"cms-expressage"})
@RestController
@RequestMapping(value = "/cms/expressage" , produces = {"application/json"})
public class ExpressageController {
    @Autowired
    private ExpressageMatchingDetailCmsService expressageMatchingDetailCmsService;
    @Autowired
    private CmsServicesCompanyInfoService cmsServicesCompanyInfoService;
    @Autowired
    private ExpressageSubscribeLogCmsService expressageSubscribeLogCmsService;

//    @ApiOperation("物流商匹配字导入")
//    @RequestMapping(value = "/import", method = RequestMethod.POST)
//    public DataOutput importExcel(@ApiParam(value = "excel文件地址", required = true) @RequestParam(value = "") String excelUrl,
//                                  @ApiParam(value = "excel文件名", required = true) @RequestParam(value = "excelFileName") String excelFileName,
//                                  @ApiParam(value = "Excel文件", required = true) @RequestParam(value = "file") MultipartFile file,
//                                  @ApiParam(value = "物流商名称", required = true) @RequestParam(value = "companyName") String companyName,
//                                  @ApiParam(value = "物流商编码", required = true) @RequestParam(value = "nameAbbr") String nameAbbr,
//                                  @ApiParam(value = "物流商logo", required = true) @RequestParam(value = "logoUrl") String logoUrl,
//                                  @ApiParam(value = "排序号码", required = true) @RequestParam(value = "idx") Integer idx,
//                                  HttpServletRequest request){
//        return expressageMatchingDetailCmsService.importExcel(file, companyName, nameAbbr, logoUrl, idx, request);
//    }

    @ApiOperation("物流商匹配字导入")
    @LogAnnotation(targetType = "expressageImport", remark = "物流商匹配字导入")
    @RequestMapping(value = "/import", method = RequestMethod.POST)
    public DataOutput importExcel(@ApiParam(value = "excel文件地址", required = true) @RequestParam(value = "excelUrl") String excelUrl,
                                  @ApiParam(value = "物流商名称", required = true) @RequestParam(value = "companyName") String companyName,
                                  @ApiParam(value = "物流商编码", required = true) @RequestParam(value = "nameAbbr") String nameAbbr,
                                  @ApiParam(value = "物流商logo", required = true) @RequestParam(value = "logoUrl") String logoUrl,
                                  @ApiParam(value = "排序号码", required = true) @RequestParam(value = "idx") Integer idx,
                                  HttpServletRequest request){
        return expressageMatchingDetailCmsService.importExcel(excelUrl, companyName, nameAbbr, logoUrl, idx, request);
    }

    @ApiOperation("获取物流商列表")
    @RequestMapping(value = "/getExpressageCompanyList", method = RequestMethod.POST)
    public PagedOutput<ServicesCompanyInfoVo> getExpressageComany(@ApiParam(value = "物流商名称") @RequestParam(value = "companyName", required = false) String companyName,
                                                                  @ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo") Integer pageNo,
                                                                  @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize") Integer pageSize){
        return cmsServicesCompanyInfoService.getServicesCompanyInfoVoList(companyName, pageNo, pageSize);
    }

    @ApiOperation("删除物流商")
    @LogAnnotation(targetType = "expressageDelete", remark = "删除物流商")
    @RequestMapping(value = "/delExpressageCompany", method = RequestMethod.POST)
    public DataOutput delExpressageCompany(@ApiParam(value = "物流公司id", required = true) @RequestParam(value = "id") Long id,
                                           HttpServletRequest request){
        return cmsServicesCompanyInfoService.delExpressageCompany(id, request);
    }

    @ApiOperation("物流商匹配字新增")
    @LogAnnotation(targetType = "expressageAdd", remark = "物流商匹配字新增")
    @RequestMapping(value = "/addMatchingKeyword", method = RequestMethod.POST)
    public DataOutput addMatchingKeyword(@ApiParam(value = "物流公司id", required = true) @RequestParam(value = "id") Long id,
                                         @ApiParam(value = "物流关键字", required = true) @RequestParam(value = "matchingKeyword") String matchingKeyword,
//                                         @ApiParam(value = "物流显示状态", required = true) @RequestParam(value = "logisticsStatusMsg") String logisticsStatusMsg,
                                         @ApiParam(value = "物流显示状态码", required = true) @RequestParam(value = "logisticsStatus") Integer logisticsStatus,
                                         HttpServletRequest request){
        return expressageMatchingDetailCmsService.addMatchingKeyword(id, matchingKeyword, logisticsStatus, request);
    }

    @ApiOperation("获取指定物流商关键字列表")
    @RequestMapping(value = "/getMatchingKeywordList", method = RequestMethod.POST)
    public PagedOutput<ExpressageMatchingDetailVo> getExpressageMatchingDetail(@ApiParam(value = "物流公司id", required = true) @RequestParam(value = "companyId") Long companyId,
                                                                               @ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo") Integer pageNo,
                                                                               @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize") Integer pageSize){
        return expressageMatchingDetailCmsService.getExpressageMatchingDetail(companyId, pageNo, pageSize);
    }

    @ApiOperation("删除快递公司的匹配字")
    @LogAnnotation(targetType = "matchingKeywordDelete", remark = "删除快递公司的匹配字")
    @RequestMapping(value = "/delMatchingKeyword", method = RequestMethod.POST)
    public DataOutput delMatchingKeyword(@ApiParam(value = "关键字id", required = true) @RequestParam(value = "id") Long id,
                                         HttpServletRequest request) {
        return expressageMatchingDetailCmsService.delExpressageMatchingDetail(id, request);
    }

    @ApiOperation("编辑快递公司匹配字")
    @LogAnnotation(targetType = "matchingKeywordUpdate", remark = "编辑快递公司匹配字")
    @RequestMapping(value = "/updateMatchingKeyword", method = RequestMethod.POST)
    public DataOutput updateMatchingKeyword(@ApiParam(value = "关键字id", required = true) @RequestParam(value = "id") Long id,
                                            @ApiParam(value = "匹配字", required = true) @RequestParam(value = "matchingKeyword") String matchingKeyword,
//                                            @ApiParam(value = "物流显示状态", required = true) @RequestParam(value = "logisticsStatusMsg") String logisticsStatusMsg,
                                            @ApiParam(value = "物流显示状态码", required = true) @RequestParam(value = "logisticsStatus") Integer logisticsStatus,
                                            HttpServletRequest request){
        return expressageMatchingDetailCmsService.updateMatchingKeyword(id, matchingKeyword, logisticsStatus, request);
    }

    @ApiOperation("获取物流节点状态枚举")
    @RequestMapping(value = "/getExpressageStatus", method = RequestMethod.POST)
    public DataOutput<List<Map<Integer, String>>> getExpressageStatus(){
        List<Map<String, Object>> list = OrderStatusEmnu.NEW_EXPRESSAGE_STATUS.getList();
        return new DataOutput(list);
    }

    @ApiOperation("Excel模板导出")
    @LogAnnotation(targetType = "excelDownload", remark = "Excel模板导出")
    @RequestMapping(value = "/download/excel", method = RequestMethod.GET)
    public void downLoadExcel(HttpServletRequest request, HttpServletResponse response){
        expressageSubscribeLogCmsService.downLoadExcel(request, response);
    }

    @ApiOperation("物流关键字excel上传")
    @RequestMapping(value = "/uploadExecl", method = RequestMethod.POST)
    public DataOutput uploadExecl(@ApiParam(value = "Excel文件", required = true) @RequestParam(value = "file") MultipartFile file,
                                  HttpServletRequest request){
        return expressageMatchingDetailCmsService.uploadExcel(file, request);
    }

}
